<template>
  <div class="content-info">
    <div class="content-item">
      <span class="info-data">{{ likes }}</span>
      <div class="content-label"><span>获得点赞数</span></div>
    </div>
    <div class="content-item">
      <span class="info-data">{{ lastUpdateTime | formatDate }}</span>
      <div class="content-label"><span>最后更新日期</span></div>
    </div>
    <div class="content-item">
      <span class="info-data">{{ articleTotal }}</span>
      <div class="content-label"><span>发布文章数</span></div>
    </div>
    <div class="content-item">
      <span class="info-data">{{ draftsTotal }}</span>
      <div class="content-label"><span>正在编辑的文章数</span></div>
    </div>
  </div>
</template>

<script>
import { api } from "@/api";
export default {
  props: ["article-total", "drafts-total"],
  data() {
    return {
      likes: 0,
      lastUpdateTime: "",
    };
  },
  methods: {
    getLastUpdateTime(id) {
      this.$axios(api.article.getLastUpdateTime(id))
        .then((result) => {
          this.lastUpdateTime = result.data;
        })
        .catch((err) => {
          if (err.response) {
            this.$alert(err.response.data.message);
          } else {
            this.$alert("网络错误");
          }
        });
    },
    getSumLikes(id) {
      this.$axios(api.article.getSumLikes(id))
        .then((result) => {
          this.likes = result.data;
        })
        .catch((err) => {
          if (err.response) {
            this.$alert(err.response.data.message);
          }
        });
    },
  },
  filters: {
    formatDate(input) {
      return new Date(input).format("yyyy-MM-dd");
    },
  },
  mounted() {
    this.getLastUpdateTime(this.$route.query.aid);
    this.getSumLikes(this.$route.query.aid);
  },
};
</script>

<style lang="less" scoped>
.content-info {
  display: flex;
  width: 900px;
  height: 300px;
  margin: 0 auto;
  margin-top: 50px;
  @media screen and (max-width: 730px) {
    flex-direction: column;
    height: 900px;
    width: 300px;
  }
  .content-item {
    text-align: center;
    border: 1px solid #409eff;
    border-radius: 5px;
    box-shadow: 3px 0px 5px gray;
    margin: 0 20px;
    flex: 1;
    font-size: 26px;
    font-weight: bold;
    .info-data {
      margin: 0 auto;
      display: block;
      line-height: 250px;
    }
    .content-label {
      background-color: #409eff;
      border-radius: 0 0 5px 5px;
      height: 50px;
      position: relative;
      width: 100%;
    }
    .content-label span {
      line-height: 50px;
      text-align: center;
      font-size: 20px;
      color: white;
    }
  }
}
</style>
